package com.mica.erp.system.service.impl;

import java.util.List;

import com.mica.erp.system.model.UserInfo;
import com.mica.erp.system.service.UserInfoService;
import com.mica.mybatis.GenericService;
import com.mica.utils.encrypt.MD5Encrypt;

public class UserInfoServiceImpl extends GenericService implements UserInfoService {

	@Override
	public UserInfo validataUser(String loginName, String passWord) {
		UserInfo ui = new UserInfo();
		ui.setLoginName(loginName);
		ui.setPassWord(MD5Encrypt.MD5(passWord));
		return this.selectOne(namespace+".loginUser", ui);
	}

	@Override
	public List<UserInfo> findUserInfos() {
		return this.selectList(namespace+".findUserInfos", null);
	}

	@Override
	public UserInfo findUserInfo(UserInfo userInfo) {
		return this.selectOne(namespace+".findUserInfos", userInfo);
	}
	
	@Override
	public void saveUserInfo(UserInfo userInfo) {
		Long userId = userInfo.getUserId();
		if(null!=userId){
			this.update(namespace+".updateUserInfo", userInfo);
		}else{
			userInfo.setUserId(this.incre.nextLongValue());
			userInfo.setStatus("1");
			this.insert(namespace+".insertUserInfo", userInfo);
		}
	}

	@Override
	public void delUserInfo(Long userId) {
		this.delete(namespace+".delUserInfo", userId);
	}

	@Override
	public void initPassWord(UserInfo userInfo) {
		this.update(namespace+".updateUserPassWord", userInfo);
	}

}
